package com.his.controller;


import com.his.commons.core.dto.Result;
import com.his.commons.core.exception.HisException;
import com.his.controller.info.DisagnosisRoomInfo;
import com.his.service.DisagnosisRoomService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 梅津铧
 * @since 2022-03-22
 */
@RestController
@RequestMapping("/disagnosisRoom")
@Api(tags = "诊室接口")
@GlobalTransactional(rollbackFor = Exception.class)
public class DisagnosisRoomController {

    @Resource
    private DisagnosisRoomService disagnosisRoomService;

    /**
     * 根据科室id获取下属诊室信息
     * @param departmentId  科室id
     */
    @ApiOperation("根据科室id获取下属诊室信息")
    @GetMapping("/obtainDisagnosisRooms/{departmentId}")
    public Result<List<DisagnosisRoomInfo>> ObtainDisagnosisRooms(@PathVariable("departmentId") Integer departmentId) throws HisException {

        List<DisagnosisRoomInfo> dis = disagnosisRoomService.obtainDisRoom(departmentId);
        if(dis.size()==0) throw new HisException("未获取到下属诊室",500);
        return Result.getInstanceList(DisagnosisRoomInfo.class).setData(dis);
    }


}

